## 30ms 3112KB 不熟练

def Isort(n,m):
    x = 0
    for i in range(1,len(n)):
       k = n[:i+1]  # 每一次都是从n截取，重新排序
       k.sort()
       k.extend(n[i+1:])  # 将未排序部分接上
       if x==1:   # 在等于中间序列的下一轮跳出
           return k
       if k==m:    #如果此时序列等于中间序列
           x = 1
    return False
 
def Msort(n,m):
    x = 0
    n = [[i] for i in n]
    while len(n)>1:
        k = []
        for j in range(0,len(n),2):
            try:
                n[j].extend(n[j+1])
                k.append(n[j])
            except:
                k.append(n[j])
        for i in k:
            i = i.sort()
        n = k[:]
        result = []
        for i in k:
            for l in i:
                result.append(l)
        if x==1:
            return result
        if result==m:
            x = 1
    
n = input()
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
aa=a.copy()
m = Isort(a,b)
if m: #!=False
    print("Insertion Sort")

else:
    m = Msort(aa,b)
    print("Merge Sort")

print(*m)